<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>字典项管理管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<style type="text/css">
		.ztree {overflow:auto;margin:0;_margin-top:10px;padding:10px 0 0 10px;};
		.nav-tabs li{cursor: pointer;}
	</style>
</head>
<body>
	<sys:message content="${message}"/>
	<div id="content" class="row-fluid">
		<div id="left" class="accordion-group">
			<div class="accordion-heading">
		    	<a class="accordion-toggle">字典项
		    		<input type="button" value="排序" onclick="sortTreeNodes()">
		    		<i class="icon-refresh pull-right" onclick="refreshTree();"></i>
		    		
		    	</a>
		    </div>
			<div id="ztree" class="ztree"></div>
		</div>
		<div id="right" >
			<ul class="nav nav-tabs">
				<li class="tabli active" link="iframeContent1"><a >字典项管理列表</a></li>
				<shiro:hasPermission name="cms:racevideo:edit">
					<li class="tabli " link="iframeContent2"><a >字典项管理详情</a></li>
				</shiro:hasPermission>
			</ul>
			<div id="iframeContentDiv">
				<iframe id="iframeContent1" name="iframe" url='${ctx}/sys/dictitem/' src="" width="100%" height="91%" frameborder="0"></iframe>
				<iframe id="iframeContent2" name="iframe" url='${ctx}/sys/dictitem/form' src="" width="100%" height="91%" frameborder="0"></iframe>
			</div>
		</div>
	</div>
	
<script type="text/javascript">
	//URL
	var listUrl = '${ctx}/sys/dictitem/';
	var cardUrl = '${ctx}/sys/dictitem/form';
	var treeUrl = '${ctx}/sys/dictitem/asyncTree';
	var treeId = 'ztree';
	var setting = {  
			view: {  selectedMulti: false }, 
			async: {  
				enable: true,  url: treeUrl+"?rk="+Math.random(),type:"GET"
				,autoParam:["id", "name", "level"]
				,async : false,  
				dataFilter: filter
			},  
			callback: {  onClick : onClickEvent }  
	}; 
	
	$(document).ready(function() {
		initTree();
		
		jQuery('.tabli').click(function(){
			changeTabs(this);
		});
		freshTabs(jQuery('[link="iframeContent1"]'));
	});
	
	function initTree(){ //初始化树
		var zNodes = [{
			"checked": false,"hasChild": true,"id": "100",
			"isParent": true,"name": "俱乐部","open": true
		}];
		$.fn.zTree.init($("#"+treeId), setting, zNodes); 
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		var nodes = treeObj.getNodes();
		if (nodes.length>0) {
			for(var i in nodes){
				treeObj.expandNode(nodes[i], true, true, true);
			}
			treeObj.selectNode(nodes[0],true);
		}
	}
	
	function filter(treeId, parentNode, childNodes) {
		if (!childNodes) return null;
		for (var i=0, l=childNodes.length; i<l; i++) {
			childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
		}
		return childNodes;
	}
	
	function onClickEvent(event, treeId, treeNode){ //单击事件  
		var id = treeNode.id == '0' ? '' :treeNode.id;
		var iframeContent1 = window.frames["iframeContent1"].document;
		
		if(id == 'root'){
			freshTabs(jQuery('[link="iframeContent1"]'));
		}else{
			if(treeNode.hasChild){
				var url = listUrl+'?dictitem.id='+id;
				freshTabs(jQuery('[link="iframeContent1"]'),url);
			}else{
				var url = listUrl+'?code='+id;
				freshTabs(jQuery('[link="iframeContent1"]'),url);
			}
			
		}
	}

	
	function refreshTree(){
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		var nodes = treeObj.getSelectedNodes();
		var node = nodes[0];
		if(node==null){return ;} //没有选择结点不刷新
		if(node.hasChild == true){  //是否有子结点
			treeObj.reAsyncChildNodes(node, "refresh");
		}
	}
	
	var leftWidth = 180; // 左侧窗口大小
	var htmlObj = $("html"), mainObj = $("#main");
	var frameObj = $("#left, #openClose, #right, #right iframe");
	function wSize(){
		var strs = getWindowSize().toString().split(",");
		htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"});
		mainObj.css("width","auto");
		frameObj.height(strs[0] - 5);
		var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
		$("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
		$(".ztree").width(leftWidth - 10).height(frameObj.height() - 46);
	}
	
	function freshTabs(obj,url){ //刷新页卡
		 jQuery('.tabli').removeClass('active');
		 jQuery(obj).addClass('active');
		 var iframeId = jQuery(obj).attr('link');
		 var iframeContents = jQuery('#iframeContentDiv').find('iframe');
		 iframeContents.css('display','none');
		 jQuery('#'+iframeId).css('display','');
		 
		 //debugger;
		 if(url!=null){
			 jQuery('#'+iframeId).attr('src',url);
		 }else{
			 jQuery('#'+iframeId).attr('src', jQuery('#'+iframeId).attr('url'));
		 }
	}
	
	function changeTabs(obj){ //切换页卡
		jQuery('.tabli').removeClass('active');
		 jQuery(obj).addClass('active');
		 var iframeId = jQuery(obj).attr('link');
		 var iframeContents = jQuery('#iframeContentDiv').find('iframe');
		 iframeContents.css('display','none');
		 jQuery('#'+iframeId).css('display','');
		 if(jQuery('#'+iframeId).attr('src') == null ||jQuery('#'+iframeId).attr('src') == ''){
			 jQuery('#'+iframeId).attr('src', jQuery('#'+iframeId).attr('url'));
		 }
	}
	
</script>
<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>
</body>
</html>